{% set prefix = DEFAULT_CONTAINER_REGISTRY %}
{%- if ARCH == "armhf" %}
FROM {{ prefix }}multiarch/qemu-user-static:x86_64-arm-6.1.0-8 as qemu
FROM --platform=linux/arm/v7 {{ prefix }}debian:{{ DIST }}
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
{%- elif ARCH == "arm64" %}
FROM {{ prefix }}multiarch/qemu-user-static:x86_64-aarch64-6.1.0-8 as qemu
FROM {{ prefix }}multiarch/debian-debootstrap:arm64-{{ DIST }}
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
{%- else -%}
FROM {{ prefix }}debian:{{ DIST }}
{%- endif %}

MAINTAINER sonicbld@microsoft.com

# Add user
ARG user
ARG uid
ARG guid
ARG hostname

ENV BUILD_HOSTNAME $hostname
ENV USER $user

RUN groupadd -f -r -g $guid g$user
RUN useradd $user -l -u $uid -g $guid -d /var/$user -m -s /bin/bash

RUN apt-get update && apt-get install -y git sudo wget

COPY [ "install-packages.sh", "/usr/bin" ]
RUN ARCH={{ ARCH }} install-packages.sh

# Config git for stg
RUN su $user -c "git config --global user.name $user"
RUN su $user -c "git config --global user.email $user@contoso.com"

# Add user to sudoers
RUN echo "$user ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers

USER $user
